using System.Collections.Generic;
using System.Data.SqlClient;

namespace OOP33rdBatchApplication
{
    internal class DepartmentGateway:DbGateway  
    {
        public List<Department> GetAll()
        {
            List<Department> departments = new List<Department>();
            string query = "SELECT * FROM t_Department";
            command.CommandText = query;
            connection.Open();
            using (SqlDataReader dataReader = command.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    Department department =new Department();
                    department.Id = int.Parse(dataReader["Id"].ToString());
                    department.Name = dataReader["Name"].ToString();
                    departments.Add(department);
                }
            }
            connection.Close();
            return departments;
        }
    }
}